import Mock from 'mockjs';

// 判断是否启用mock
const isMock = new URLSearchParams(window.location.search).has('mock');

if (isMock) {
    // 示例接口mock数据
    Mock.mock(/\/api\/products/, 'get', {
        'code': 200,
        'data|10': [
            {
                'id|+1': 1,
                'name': '@ctitle(5, 10)',
                'description': '@cparagraph(1, 3)',
                'price|100-1000': 100,
                'image': '@image(200x200)'
            }
        ]
    });

    Mock.mock(/\/api\/news/, 'get', {
        'code': 200,
        'data|5': [
            {
                'id|+1': 1,
                'title': '@ctitle(10, 20)',
                'content': '@cparagraph(2, 4)',
                'date': '@date("yyyy-MM-dd")',
                'author': '@cname'
            }
        ]
    });

    console.log('Mock服务已启动');
}
